package logica;

import java.util.ArrayList;
import java.util.Iterator;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="Obstaculos")
public class Obstaculos {

	private ArrayList<Obstaculo> lista;
	
	public Obstaculos() {
		lista = new ArrayList<Obstaculo>();
	}
	
	public Obstaculos(ArrayList<Obstaculo> lista) {
		this.lista = lista;
	}

	public ArrayList<Obstaculo> getLista() {
		return lista;
	}

	public void setLista(ArrayList<Obstaculo> lista) {
		this.lista = lista;
	}
	
	public Obstaculo getObstaculo(int id){
		
		Iterator<Obstaculo> it = lista.iterator();
		boolean encontrado = false;
		Obstaculo ob = null;
		
		while(it.hasNext() && encontrado){
			ob = it.next();
			if(ob.getId() == id)
				encontrado = true;
		}
		
		return ob;
	}
	
	public void setObstaculo(Obstaculo ob){
		lista.add(ob);
	}
	
	//ARREGLO
	public void deleteObstaculo(int id){
		Iterator <Obstaculo> it = lista.iterator();
		int i = 0;
		while(it.hasNext()){
			Obstaculo o = it.next();
			if(o.getId() == id){
				lista.remove(i);
				break;
			}
			i++;
		}
	}
	//

}
